package cn.funeralobjects.util.converter;

import javax.persistence.AttributeConverter;

/**
 * 默认的boolean -> number转换器
 *
 * @author FuneralObjects
 * Create date: 2020/4/15 6:25 AM
 */
public class DefaultBooleanNumberConverter implements AttributeConverter<Boolean, Number> {
    @Override
    public Number convertToDatabaseColumn(Boolean attribute) {
        return attribute == null ? null : attribute ? 1 : 0;
    }

    @Override
    public Boolean convertToEntityAttribute(Number dbData) {
        return dbData == null ? null : dbData.byteValue() != 0;
    }
}
